﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Net;
using System.Text;

namespace ManageBanking.Models
{
    public class MailModels
    {
        private OnlineBankingDataContext olbk = new OnlineBankingDataContext();

        public void SentMail(string emailto,int type,out string pass)
        { 
                    MailMessage mm = new MailMessage();
                    pass = RandomString();
                    mm.From = new MailAddress("chickenbank.aptech@gmail.com", "Le Long Hung");
                    mm.To.Add(emailto.Trim());
                    if (type == 1)
                    {
                       
                        mm.Subject = "Chicken Bank,Take Back Your Password";
                        mm.Body = "Thank you for trusting our bank We just receive your request for taking back password.Your New Password Is:   "+pass;
                    }
                    if (type == 2)
                    {
                        mm.Subject = "Chicken Bank,Your Request Is Reolved";
                        mm.Body = "We Just Receive Your Request For Unlocking your username,after considering your situation your request is solved,you are unlocked";
                    }

                    //gui di
                    SmtpClient server = new SmtpClient("smtp.gmail.com");
                    server.Port = 587;
                    server.Credentials = new NetworkCredential("chickenbank.aptech@gmail.com", "123456aptech");
                    // ma hoa 
                    server.EnableSsl = true;
                    server.Send(mm);
                    
        
        }
        private string RandomString()
        {
            StringBuilder builder = new StringBuilder();
            Random random = new Random();
            char ch;
            for (int i = 0; i < 8; i++)
            {
                ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
                builder.Append(ch);
            }

            return builder.ToString();
        }

       
    }
}
